import request from './request'

// 审计日志相关接口
export interface AuditLogQueryParams {
  actionType?: string
  module?: string
  keyword?: string
  startTime?: string
  endTime?: string
  userId?: number
  result?: string
  pageDto: {
    pageNumber: number
    pageSize: number
  }
}

export interface AuditLogDto {
  id: number
  actionType: string
  module: string
  description: string
  userId: number
  userName: string
  account: string
  targetId?: number
  targetName: string
  oldValues?: string
  newValues?: string
  clientIp?: string
  userAgent?: string
  result: string
  errorMessage?: string
  actionTime: string
  createdAt: string
  updatedAt: string
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  page: number
  pageSize: number
  totalPages: number
}

export interface ApiResponse<T = any> {
  message: string
  data?: T
  code: number
}

// 分页查询审计日志
export function getAuditLogList(params: AuditLogQueryParams) {
  return request.post<ApiResponse<PagedResult<AuditLogDto>>>('/auditlog/getList', params)
}

// 获取用户最近的日志
export function getRecentLogs(userId: number, count: number = 10) {
  return request.post<ApiResponse<AuditLogDto[]>>(`/auditlog/getRecentLogs`, { id: userId, count: count })
}

// 获取操作类型列表
export function getActionTypes() {
  return request.get<ApiResponse<Array<{ value: string; label: string }>>>('/auditlog/getActionTypes')
}

// 获取模块列表
export function getModules() {
  return request.get<ApiResponse<Array<{ value: string; label: string }>>>('/auditlog/getModules')
}
